import numpy as np 

# 1->a, 2->b, 3->c
# a,b,c,d,e = range(1,5) #节点序号（1,2,3,4,5）
# node=[1,2,3,4,5]
# data = [  [1, 2]
#         , [1, 5]
#         , [2, 3]
#         , [2, 4]
#         , [3, 4]
#         , [3, 5]
#         , [4, 5]]


a,b,c,d,e = range(5)
data = [  [a, b]
        , [a, e]
        , [b, c]
        , [b, d]
        , [c, d]
        , [c, e]
        , [d, e]]

data = np.array(data)

# 返回某个节点的连接情况
def find_node_links(node, data):
    data_new = data[:,:1]          # 列 截取
    print(data_new)

    data_new = data_new.ravel('F') # 列 降维
    print(data_new)
    re = np.where(data_new == node) # 返回索引号
    print(re)

# 创建一个邻接矩阵
data_matrix = np.zeros((5,5),dtype=int)
print(data_matrix)
# 生成邻接矩阵，（遍历数据）
for i in range(len(data)):
    temp1 = data[i][0]
    temp2 = data[i][1]
    print(temp1, temp2)

    data_matrix[temp1][temp2] = 1 #正向 连接
    data_matrix[temp2][temp1] = 1 #反向 连接

print(data_matrix)


#find_node_links(3, data)
